package cn.com.api.controller;

import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiT_member_task_process;

import cn.com.api.service.ApiT_member_task_processService;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "t_member_task_process/")
public class ApiT_member_task_processController {
    @Autowired
    private ApiT_member_task_processService apiT_member_task_processService;
	
	private static Logger logger = Logger.getLogger(ApiT_member_task_processController.class);
	
	/**
	 * 新增
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "insertT_member_task_process")
	public void insertT_member_task_process(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String process_id = request.getParameter("process_id");
		String user_id = request.getParameter("user_id");
		String task_id = request.getParameter("task_id");
		String dead_time = request.getParameter("dead_time");
		String curr_partner_count = request.getParameter("curr_partner_count");
		String curr_ent_count = request.getParameter("curr_ent_count");
		String curr_advert_money = request.getParameter("curr_advert_money");
		String frozen_money = request.getParameter("frozen_money");
        
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(process_id!=null && !"".equals(process_id.trim())){
				ApiT_member_task_process t_member_task_process = new ApiT_member_task_process();
				
    		    //t_member_task_process.setProcess_id(process_id);
    		    //t_member_task_process.setUser_id(user_id);
    		    //t_member_task_process.setTask_id(task_id);
    		    //t_member_task_process.setDead_time(dead_time);
    		    //t_member_task_process.setCurr_partner_count(curr_partner_count);
    		    //t_member_task_process.setCurr_ent_count(curr_ent_count);
    		    //t_member_task_process.setCurr_advert_money(curr_advert_money);
    		    //t_member_task_process.setFrozen_money(frozen_money);
				
				apiT_member_task_processService.insertT_member_task_process(t_member_task_process);
				// return
                map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加成功！");
			}
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 根据id查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_member_task_processById")
	public void findT_member_task_processById(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		try{
		    String id = request.getParameter("id");
		    ApiT_member_task_process t_member_task_process = apiT_member_task_processService.findT_member_task_processById(Integer.valueOf(id));
		
			// return
            map.put("datas", t_member_task_process);
            map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
        
	}
	
     /**
	 * 查询数据集
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_member_task_processs")
	public void findT_member_task_processs(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		try{
		    List<ApiT_member_task_process> t_member_task_processs = apiT_member_task_processService.findT_member_task_processs();
		
			// return
            map.put("datas", t_member_task_processs);
            map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
        
	}
	
    
	/**
	 * 修改
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@Transactional
	@RequestMapping(value = "updateT_member_task_process")
	public void updateT_member_task_process(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String process_id = request.getParameter("process_id");
		String user_id = request.getParameter("user_id");
		String task_id = request.getParameter("task_id");
		String dead_time = request.getParameter("dead_time");
		String curr_partner_count = request.getParameter("curr_partner_count");
		String curr_ent_count = request.getParameter("curr_ent_count");
		String curr_advert_money = request.getParameter("curr_advert_money");
		String frozen_money = request.getParameter("frozen_money");
        
        
		//String id = request.getParameter("id");
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(process_id!=null && !"".equals(process_id.trim())){
				ApiT_member_task_process t_member_task_process = new ApiT_member_task_process();
				//获取原数据
				t_member_task_process  = apiT_member_task_processService.findT_member_task_processById(Integer.valueOf(process_id));
				//修改
				//t_member_task_process.setIs_open(Integer.valueOf(is_open));
				//
				int ret_i = apiT_member_task_processService.updateT_member_task_process(t_member_task_process);
				
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "编辑成功！");
			}else{
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "检查失败！");
			}
		}
		catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
    
	/**
	 * 删除
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "deleteT_member_task_process")
	public void deleteT_member_task_process(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
        String id = request.getParameter("id");
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(id!=null && !"".equals(id.trim())){
	
				Integer ret_I = apiT_member_task_processService.deleteT_member_task_process(Integer.parseInt(id));
				if(ret_I >0 ){
    				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
    				map.put(Utils.MESSAGE, "删除成功！");
                }else{
				    map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				    map.put(Utils.MESSAGE, "检查失败！");
			    }
			}
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
 
}


